using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

namespace shfa.snomtastic.data
{
    public partial class SqlDataProvider
    {

        public Guid InsertModel(string name, string errorMessage, Guid configurationId)
		{
            return new Guid(Convert.ToString(SqlHelper.ExecuteScalar(ConnectionString, "sp_ModelInsert", name, errorMessage, GetNull(configurationId))));
		}

        public int UpdateModel(Guid modelId, string name, string errorMessage, Guid configurationId)
		{
            return Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionString, "sp_ModelUpdate", GetNull(modelId), name, errorMessage, GetNull(configurationId)));
		}

        public int DeleteModel(Guid modelId) 
		{
            return Convert.ToInt32(SqlHelper.ExecuteScalar(ConnectionString, "sp_ModelDelete", modelId));
		}

        public DataRow SelectModel(Guid modelId) 
        {    
			DataSet ds = SqlHelper.ExecuteDataset(ConnectionString, "sp_ModelSelect", modelId);
            if (ds.Tables.Count > 0)
                if (ds.Tables[0].Rows.Count > 0)
                    return ds.Tables[0].Rows[0];

            return null;
		}

		public DataTable SelectModels() 
		{
            return SqlHelper.ExecuteDataset(ConnectionString, "sp_ModelSelectAll").Tables[0];
        }

		public DataTable SelectModelsByConfiguration(Guid configurationId) 
		{
            return SqlHelper.ExecuteDataset(ConnectionString, "sp_ModelSelectByConfiguration", configurationId).Tables[0];
        }

    }

}
